package com.osc.exam.config;

import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 分页插件封装
 * @param <T>
 */
public class PageBean<T> {

    private Integer pageSize;
    private Integer total;
    private Integer page;

    private List<T> list;

    public PageBean() {
    }

    public PageBean(Integer pageSize, Integer total, Integer page, List<T> list) {
        this.pageSize = pageSize;
        this.total = total;
        this.page = page;
        this.list = list;
    }

    public static <T> PageBean<T> of(List<T> data, PageInfo<T> info) {
        return new PageBean<>(info.getPageSize(), (int) info.getTotal(), info.getPageNum(), data);
    }

    public static <T, R> PageBean<T> ofWrapped(List<T> data, PageInfo<R> info) {
        return new PageBean<>(info.getPageSize(), (int) info.getTotal(), info.getPageNum(), data);
    }

    public static <T, A> PageBean<T> ofOther(List<T> data, PageBean<A> other) {
       return new PageBean<>(other.getPageSize(), other.getTotal(), other.getPage(), data);
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
